from .models import Article
import django_filters
from apps.system.models import Category

class ArticleFilter(django_filters.FilterSet):
    id = django_filters.CharFilter(field_name='id')
    title = django_filters.CharFilter(field_name='title', lookup_expr='icontains')
    content = django_filters.CharFilter(field_name='content', lookup_expr='icontains')
    author = django_filters.CharFilter(field_name='author__name', lookup_expr='icontains')
    category = django_filters.CharFilter(field_name='category')
    tags = django_filters.CharFilter(method='find_base_tags')

    class Meta:
        model = Article
        fields = ('title', 'content', 'status', 'category', 'author', 'tags')

    def find_base_tags(self, request, *args):
        print(list(args[1]))
        print(Article.objects.filter(tags__in=[1,2,3]))
        return Article.objects.filter(tags__in=list(args[1]))


